package com.ukao.pad.bean;

import android.os.Parcel;
import android.os.Parcelable;

import com.ukao.pad.eventbus.MainEvent;
import com.ukao.pad.utils.T;


import java.util.ArrayList;
import java.util.List;

import static com.ukao.pad.eventbus.MainEvent.Message.login;

/**
 * Created by ukaodev on 2017/6/29.
 */

public class BaseListBean<E> implements  Parcelable {

    public int httpCode;
    public String msg;
    public List<E> data;


    public static final Creator<BaseListBean> CREATOR = new Creator<BaseListBean>() {
        @Override
        public BaseListBean createFromParcel(Parcel in) {
            return new BaseListBean(in);
        }

        @Override
        public BaseListBean[] newArray(int size) {
            return new BaseListBean[size];
        }
    };

    public int getHttpCode() {
        /*401 未登录 403 无效的accessToken*/

            if (httpCode==403||httpCode==401){

                MainEvent.postNoData(login);


        }
        return httpCode;
    }

    public String getMsg() {
        return msg;
    }

    public List<E> getData() {
        return data;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.httpCode);
        dest.writeString(this.msg);
        dest.writeList(this.data);
    }
    public BaseListBean() {

    }
    protected BaseListBean(Parcel in) {
        this.httpCode = in.readInt();
        this.msg = in.readString();
        this.data = new ArrayList<E>();
        in.readList(this.data, T.class.getClassLoader());
    }

}
